home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / vol3 / no3 / sumofrec.prg < prev    next >
Text File  |  1988-11-01  |  1KB  |  42 lines

  1. * Program: SumOfRec.prg
  2. * Author:  Grant Nesheim
  3. * Version: Clipper Summer '87
  4. * Note(s): Perform the sum of reciprocals test using four
  5. *          methods for comparing the results to determine
  6. *          which method is best.
  7. *
  8. * Copyright (c) 1988 Nantucket Corp.
  9.  
  10. CLEAR
  11. @ 1,0 SAY "Sum of reciprocals with various comparison methods."
  12. @ 3,0 SAY " A - sum == 1.00"
  13. @ 4,0 SAY " B - ABS(sum-1.00) < epsilon  (epsilon = 10^-15)"
  14. @ 5,0 SAY " C - ROUND(sum,2) = 1.00"
  15. @ 6,0 SAY " D - VAL(STR(sum,4,2)) = 1.00"
  16. @ 8,0 SAY " N     Sum   A   B   C   D"
  17. @ 9,0 SAY " -------------------------"
  18.  
  19. epsilon = 10^-15
  20. FOR i = 1.00 TO 15.00
  21.    sum = 0.00
  22.    FOR j = 1.00 TO i
  23.       sum = sum + 1/i
  24.    NEXT
  25.  
  26.    * Use the straight forward method for testing equality.
  27.    a = IF(sum == 1.00,"T","F")
  28.  
  29.    * Use the machine epsilon to method to test equality.
  30.    b = IF(ABS(sum-1.00) < epsilon,"T","F")
  31.  
  32.    * Use ROUND() to test for equality.
  33.    c = IF(ROUND(sum,2) == 1.00,"T","F")
  34.  
  35.    * Use the string function to test for equality.
  36.    d = IF(VAL(STR(sum,4,2)) == 1.00,"T","F")
  37.  
  38.    @ 9+INT(i), 0 SAY STR(i,5,2)+" "+STR(sum,4,2)
  39.    @ 9+INT(i), 13 SAY a + "   " + b + "   " + c + "   " + d
  40. NEXT
  41. RETURN
  42.